import numpy as np


'''Fighter
data = {
    'attr': {
        #Essence, Qi, and Spirit
        'E': 0,
        'Q': 0,
        'S': 0,
        'hp': 0,
        'mp': 0
   }
    'buf': [
        #buf-type, in attr.b.keys() + attr.a.keys()
        #value, float(v) or str(%)
        #expiration-time, if age >= ex-time, del buf
        (<buf-type>, <value>, <Expiration-Time>),
    ],
    'cond': [
        #condition-class, code for every condition
        #condition status in para
        #condition.refresh(), if return True, del cond
        (condition-class, condition-para)
    ],
    'skills': {
        'caltural': { #caltural, add Spirit
        },
        'basic': { #basic, add Essence/Qi
        }
        'advanced': { #advanced
        }
    },
    'advanced': { #advanced
        'max_hp': f(E, Q),
        'max_mp': f(E, S),
        #attack speed
        'AS': f(E, Q, S),
        #Damage and Resistance
        #Physical, Elemental and Mental
        'PD': 0,
        'ED': 0,
        'MD': 0,
        'PR': 0,
        'ER': 0,
        'MR': 0,
        #hp/mp Regeneration
        'hr': 0,
        'mr': 0
    }
}
'''


class Fighter:
    def __init__(self, master, uid):
        self.m = master
        self.uid = uid
        self.data = None


    def init_data(self):
        data = {
            'attr': {
                'E': 100,
                'Q': 100,
                'S': 100,
                'hp': 0,
                'mp': 0
            }
        }
        return data


    def _buf(self, v, attr:str):
        v += sum([_[1] for _ in self.buf if _[0] == tag])
        v *= 1 + sum([_[1] for _ in self.buf if _[0] == f'_{tag}'])
        return int(v) 


    @property
    def buf(self):
        return self.data.get('buf', [])


    @property
    def cond(self):
        return self.data.get('cond', [])


    @property
    def skills(self):
        return self.data.get('skills', {})


    @property
    def sk_c(self):
        return self.skills.get('caltural', {})


    @property
    def sk_b(self):
        return self.skills.get('basic', {})


    @property
    def sk_a(self):
        return self.skills.get('advanced', {})


    @property
    def E(self):
        v = self.data['attr']['basic']['E']
        return self._buf(v, 'E')


    @property
    def Q(self):
        v = self.data['attr']['Q']
        return self._buf(v, 'Q')


    @property
    def S(self):
        v = self.data['attr']['S']
        return self._buf(v, 'S')


    @property
    def hp(self):
        return self.data['attr']['hp']


    @property
    def mp(self):
        return self.data['attr']['mp']


    @property
    def max_hp(self):
        v = self.E*100 + self.Q*50
        return self._buf(v, 'max_hp')


    @property
    def max_mp(self):
        v = self.S*100 + self.Q*50
        return self._buf(v, 'max_mp')


    @property
    def AS(self):
        v = self.E*self.Q*self.S
        v = np.cbrt(v)
        return self._buf(v, 'AS')


    @property
    def PD(self):
        v = self.E + self.Q
        return self._buf(v, 'PD')


    @property
    def ED(self):
        v = self.Q*2
        return self._buf(v, 'ED')


    @property
    def MD(self):
        v = self.S + self.Q
        return self._buf(v, 'MD')


    @property
    def PR(self):
        v = self.E + self.Q
        return self._buf(v, 'PR')


    @property
    def ER(self):
        v = self.Q*2
        return self._buf(v, 'ER')


    @property
    def MR(self):
        v = self.S + self.Q
        return self._buf(v, 'MR')


    @property
    def hpr(self):
        v = self.E + self.Q*2
        return self._buf(v, 'hpr')


    @property
    def mpr(self):
        v = self.S + self.Q*2
        return self._buf(v, 'mpr')
 

    @property
    def atype(self):
        '''attack type
        - Physical,
            0. unarmed
            1. spear
            2. staff
            3. blade
            4. sword
            5. hammer
            6. axe
            7. dagger
            8. whip
            9. throwing
            10. odd
        - Elemental
            - spells
        - Mental
            - music
        '''
        return 'unarmed'


    @property
    def prof(self):
        '''proficiency from basic skills
        '''
        return 0


    @property
    def power(self):
        '''power from advanced skills
        '''
        return 0
    

    def status(self):
        s = self.m.Style
        msg = f'[E] {self.E:<11}[Q] {self.Q:<11}[S] {self.S}\n'
        hp = f'{self.hp}/{self.max_hp}'
        mp = f'{self.mp}/{self.max_mp}'
        msg += f'{s.HR}[hp] {hp:<23}{s.HB}[mp] {mp}{s.N}\n'
        msg += f'[AS] {self.AS:<10}[hpr] {self.hpr:9}[mpr] {self.mpr}\n'
        msg += f'[PD] {self.PD:<10}[ED] {self.ED:10}[MD] {self.MD}\n'
        msg += f'[PR] {self.PR:<10}[ER] {self.ER:10}[MR] {self.MR}\n'
        return msg


